﻿using MediatR;
using Traceability.App.Apilication.Common.Deep;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler.Deep
{
    public class GetDeepEnterHandler : IRequestHandler<GetDeepEnterCommon, ApiResult<List<DeepEnterprisess>>>
    {
        private readonly IBaseRespository<DeepEnterprisess> deepEnterprisessRepo;

        public GetDeepEnterHandler(IBaseRespository<DeepEnterprisess> DeepEnterprisessRepo)
        {
            deepEnterprisessRepo = DeepEnterprisessRepo;
        }
        public Task<ApiResult<List<DeepEnterprisess>>> Handle(GetDeepEnterCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<DeepEnterprisess>> res = new ApiResult<List<DeepEnterprisess>>();

            var info = deepEnterprisessRepo.GetAll().Where(x => x.Production_Batch == request.Production_Batch).ToList();

            res.Message = "根据生产批次查询深加工企业信息";
            res.Code = ApiEnum.Success;
            res.Data = info;
            return Task.FromResult(res);
        }
    }
}
